//
//  UTOTPConfiguration.m
//  OTPGenerator
//
//  Created by 武探 on 2017/3/30.
//  Copyright © 2017年 wutan. All rights reserved.
//

#import "UTOTPConfiguration.h"

const uint32_t UTOTP_digitsModLut[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 };
const uint32_t UTOTP_defaultDigits = 6;

@implementation UTOTPConfiguration

-(instancetype)initWithSecret:(NSData *)secret {
    self = [super init];
    if(self) {
        _secret = secret;
        _digits = UTOTP_defaultDigits;
        _digitsMod = UTOTP_digitsModLut[_digits];
        _defaultInterval = 60;
    }
    return self;
}

-(instancetype)initWithSecret:(NSData *)secret digits:(uint32_t)digits {
    self = [super init];
    if(self) {
        _secret = secret;
        digits = digits < 6 ? 6 : digits > 8 ? 8 : digits;
        _digits = digits;
        _digitsMod = UTOTP_digitsModLut[_digits];
        _defaultInterval = 60;
    }
    return self;
}

@end
